package com.zyh.scs.admin.base.open;

import com.zyh.scs.admin.api.constant.open.OpenResponseCode;
import lombok.Data;
import lombok.ToString;

import java.io.Serializable;

/**
 * @author hwh
 * @param <T>
 */
@Data
@ToString
public class AccountResponse<T> implements Serializable {

	/**
	 *
	 */
	private static final long serialVersionUID = 1L;

	protected Integer errCode;

	protected String errMsg;

	protected String traceId;

	protected T data;

	public AccountResponse(){
		this.errCode = OpenResponseCode.SYSTEM_EXCEPTION.getCode();
		this.errMsg = "处理失败";
		this.traceId = "";
	}

	public AccountResponse(Integer code, String msg, String traceId){
		this.errCode = code;
		this.errMsg = msg;
		this.traceId = traceId;
	}

	public static <T> AccountResponse<T> success(String msg, String traceId){
		AccountResponse<T> result = new AccountResponse<>();
		result.setErrCode(OpenResponseCode.SUCCESS.getCode());
		result.setErrMsg(msg);
		result.setTraceId(traceId);
		return result;
	}

	public static <T> AccountResponse<T> error() {
		AccountResponse<T> result = new AccountResponse<>();
		result.setErrCode(OpenResponseCode.SYSTEM_EXCEPTION.getCode());
		result.setErrMsg("系统处理失败");
		result.setTraceId("");
		return result;
	}

	public static <T> AccountResponse<T> error(OpenResponseCode responseCode, String traceId){
		AccountResponse<T> result = new AccountResponse<>();
		result.setErrCode(responseCode.getCode());
		result.setErrMsg(responseCode.getCodeName());
		result.setTraceId(traceId);
		return result;
	}

	public static <T> AccountResponse<T> error(Integer errCode, String errMsg, String traceId){
		AccountResponse<T> result = new AccountResponse<>();
		result.setErrCode(errCode);
		result.setErrMsg(errMsg);
		result.setTraceId(traceId);
		return result;
	}

}